package com.pzhu;

import com.pzhu.config.*;
import com.pzhu.dao.BookDao;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;

import javax.sql.DataSource;

/**
 * @author Yancy xiao
 * @create 2023-04-17 9:05
 */
public class Test {
    public static void main(String[] args) {
        //1.拿到IOC容器
        AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(SpringConfig.class);
        //2.从容器中获取相应的bean对象
        BookDao bookDao = ctx.getBean(BookDao.class);

        //测试@Scope("prototype")
//        BookDao bookDao1 = ctx.getBean(BookDao.class);
//        System.out.println(bookDao);
//        System.out.println(bookDao1);

        //测试生命周期
//        bookDao.save();
//        ctx.close();

        //测试Value依赖注入
        bookDao.save();

        //测试数据源对象管理
        DataSource dataSource = ctx.getBean(DataSource.class);
        System.out.println(dataSource);
    }
}